<?php
//+---------
//|缓存类
//+---------
class Cache {
	/**
	 * Memcache生成缓存
	 * @see ICache::Memcaches()
	 */
	protected $memcache;
	function __construct(){
		if ($this->clientMemcache()==false)
		  die("Memcache连接失败");
	}
	/**
	 * 设置缓存
	 * @see ICache::setMemcache()
	 */
	public function setMemcache($content,$key){		
		try {
			$expire=(int)C("memcache_expire");			
			return $this->memcache->set($key,$content,MEMCACHE_COMPRESSED,$expire); 
		}catch (Exception $e){
			exit($e->getMessage());
		}
	}
	/**
	 * 获取缓存
	 * @see ICache::getMemcache()
	 */
	public function getMemcache($key){
		try {
			return $this->memcache->get($key,2);
		}catch (Exception $e){
			die($e->getMessage());
		}
	}
	/**
	 * 删除memcache缓存
	 * @see ICache::delMemcache()
	 */
	public function delMemcache($key){
		try {
			return $this->memcache->delete($key,0);
		}catch (Exception $e){
			die($e->getMessage());
		}
	}
	//连接Memcache
	protected function clientMemcache(){
		$this->memcache= new Memcache;
		return $this->memcache->connect(C("memcache_host"), (int)C("memcache_prot"))?true:false;		
	}
}
?>